
import Vue from 'vue'

export default Vue.directive('has', {  //在原型链上添加一个指令 v-has
    inserted: function (el, binding) {
        if (!Vue.prototype.$_has(binding.value)) {
            el.parentNode.removeChild(el);
        }
    }
});

Vue.prototype.$_has = function (value) {
    let isExist = false;
    let buttonpermsStr = localStorage.buttenpermissions;   
    if (buttonpermsStr == undefined || buttonpermsStr == null) {   //后台返回的 buttenpermissions 权限应该是一个数组，["sys_user_save","sys_user_save"]
        return false;
    }
    let buttonperms = buttonpermsStr.split(",");
    for (let i = 0; i < buttonperms.length; i++) {
        if (buttonperms[i] == value) {  //对比，有这个权限标识有返回true
            isExist = true;
            break;
        }
    }
    return isExist;
};